<?php
    namespace Home\Controller;
    use Think\Controller;
    class LoginController extends Controller {
		
		public function _initialize()
		{
		    header("Access-Control-Allow-Origin: *");  
		
		    header("Access-Control-Allow-Credentials: true"); 
		  
		    header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS"); //允许的请求类型
		    
		    header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept"); 
		
		}
		
		public function login()
		{
			$username = I('post.username');
			$password = I('post.password');
			
			$data['db_user'] = $username;
			$data['password'] = md5($password);
			
			$info = M('comm.sys_users')->where($data)->find();
			unset($data);
			if(!empty($info))
			{
				$data['uuid'] = $info['uuid'];
				$data['db_user'] = $info['db_user'];
				$data['username'] = $info['username'];
				$data['role_id'] = $info['role_id'];
				$data['dept_list'] = $info['dept_list'];
				
				$data['msg'] = "登录成功";
				$data['code'] = 0;
				
			}
			else
			{
				$data['msg'] = "账号密码错误,请重试";
				$data['code'] = -1;
			}
			$json['data'] = $data;
			$this->ajaxReturn($json,'json');
		}
	}
	
	